<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" th:href="@{/adminlte/layui/css/layui.css}"  media="all"/>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<!--<div class="layui-btn-group demoTable">
    <button class="layui-btn" data-type="getCheckData">获取选中行数据</button>
    <button class="layui-btn" data-type="getCheckLength">获取选中数目</button>
    <button class="layui-btn" data-type="isAll">验证是否全选</button>
</div>-->
<!--<h3 style="margin-top: -10px; margin-left:-10px;">检测入库</h3>-->
<div class="demoTable">
    所在地区：
    <div class="layui-inline" style="width: 220px">
        <select name="localSearch2" lay-verify=""  style="width: 200px" onchange="supplierNameSearch()">
            <option value="">请选择所在地区</option>
        </select>
    </div>
    <div class="layui-inline" style="margin-left: -15px">供应商名称：</div>
    <div class="layui-inline" style="width: 220px;">
        <select name="supplierNameSearch2" lay-verify=""  style="width: 200px" onchange="goodsType()">
            <option value="">请选择供应商名称</option>
        </select>
    </div>
    物料类别：
    <div class="layui-inline" style="width: 220px">
        <select name="goodsTypeSearch2" lay-verify=""  style="width: 200px" onchange="goodsName()">
            <option value="">请选择物料类别</option>
        </select>
    </div>
    物料名称：
    <div class="layui-inline" style="width: 220px">
        <select name="goodsNameSearch2" lay-verify=""  style="width: 200px" onchange="specifications()">
            <option value="">请选择物料名称</option>
        </select>
    </div><br/>
    物料规格：
    <div class="layui-inline" style="width: 220px">
        <select name="specificationsSearch2" lay-verify=""  style="width: 200px" >
            <option value="">请选择物料规格</option>
        </select>
    </div>
    起始日期：
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="startDateSearch" autocomplete="off" style="width: 200px;height: 25px" placeholder="请选择起始日期"/>
    </div>
    截止日期：
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="endDateSearch" autocomplete="off" style="width: 200px;height: 25px" placeholder="请选择截止日期"/>
    </div>
    <button class="layui-btn layui-btn-sm" data-type="reload">查询</button>
</div>
<!--<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="upload" id="upload" >导入</button>
    </div>
</script>-->
<table class="layui-table" lay-data="{totalRow:true,url:'/goodStock/goodStockData', page:true, id:'idTestStock',toolbar: 'true',defaultToolbar:['exports'] }" lay-filter="demoStock">
    <thead>
    <tr>
        <!--<th lay-data="{type:'checkbox', fixed: 'left'}"></th>-->
        <th lay-data="{field:'goodsType', width:150, sort: true}">物料类别</th>
        <th lay-data="{field:'goodsName', width:150,sort: true}">物料名称</th>
        <th lay-data="{field:'specifications', width:150,sort: true}">物料规格</th>
        <th lay-data="{field:'goodsStock', width:150 ,totalRowText:'合计：'}">库存仓库</th>
        <th lay-data="{field:'nums', width:150,totalRow:true}">库存数量</th>
        <th lay-data="{field:'supplierName', width:150}">供应商名称</th>
        <th lay-data="{field:'operator', width:150}">操作人</th>
        <th lay-data="{field:'operatorTime', width:180}">操作时间</th>
        <th lay-data="{field:'remarks', width:500}">备注</th>
    </tr>
    </thead>
</table>
<div id="add-mainStock" style="display: none;">
    <div class="my-form">
        <form class="layui-form" action="/user/add" method="POST" lay-skin="line">
            <div class="layui-form-item my-form-item">
                <label class="layui-form-label layui-icon">&#xe770;</label>
                <div class="layui-input-inline">
                    <input id="name" type="text" name="name" lay-verify="required" placeholder="请输入用户名" autocomplete="off"
                           class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item my-form-item">
                <label class="layui-form-label layui-icon">&#xe673;</label>
                <div class="layui-input-inline">
                    <input id="password" type="text" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off"
                           class="layui-input"/>
                </div>
            </div>
        </form>
    </div>
</div>
<script th:src="@{/adminlte/layui/layui.js}" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demoStock)', function(obj){
            console.log(obj)
        });
        var $ = layui.$, active = {
            /*     getCheckData: function(){ //获取选中数据
                     var checkStatus = table.checkStatus('idTest')
                         ,data = checkStatus.data;
                     layer.alert(JSON.stringify(data));
                 }
                 ,getCheckLength: function(){ //获取选中数目
                     var checkStatus = table.checkStatus('idTest')
                         ,data = checkStatus.data;
                     layer.msg('选中了：'+ data.length + ' 个');
                 }
                 ,isAll: function(){ //验证是否全选
                     var checkStatus = table.checkStatus('idTest');
                     layer.msg(checkStatus.isAll ? '全选': '未全选')
                 }
                 ,*/
            reload:function () {
                var local = $("[name='localSearch2'] option:selected").text();
                var supplierName = $("[name='supplierNameSearch2'] option:selected").text();
                var goodsType = $("[name='goodsTypeSearch2'] option:selected").text();
                var goodsName = $("[name='goodsNameSearch2'] option:selected").text();
                var specifications = $("[name='specificationsSearch2'] option:selected").text();
                var startDate = $("#startDateSearch").val();
                var endDate = $("#endDateSearch").val();
                table.reload('idTestStock',{
                    url:'/goodStock/searchGoodsStock',
                    where:{local:local,supplierName:supplierName,goodsType:goodsType,goodsName:goodsName,specifications:specifications,startDate:startDate,endDate:endDate}  ,
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })

            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    layui.use(['upload'],function(){
            var $ = layui.jquery,
                upload = layui.upload;
//指定允许上传的文件类型
            upload.render({
                elem: '#upload'
                ,url: '/goods/upload'
                ,accept: 'file' //普通文件
                ,exts: 'xlsx' //只允许上传excel文件
                ,done: function(res){
                    if(res.code == 0){ //上传成功
                        layer.msg(res.msg);

                    }else{
                        layer.msg('上传失败');
                    }
                   /* tabInst.reload();*/
                }
                ,error: function(index, upload){
                    layer.msg('上传失败');
                }
            });
        });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#startDateSearch' //指定元素
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#endDateSearch' //指定元素
            ,type: 'datetime'
        });
    });
    $(
        function () {
            loadSelect();
        }
    )
    function loadSelect() {
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/querySupplierLocal" ,//url
            success: function (result) {
                if (result.success>0) {
                    var list =result.date;
                    $("[name='localSearch2']").empty();
                    var op="";
                    var bp="请选择所在地区";
                    $("[name='localSearch2']").append("<option value="+op+">"+bp+"</option>");
                    $.each(list,function (i,val) {
                        $("[name='localSearch2']").append("<option value="+val+">"+val+"</option>");
                        $("#localAdd").append("<option value="+val+">"+val+"</option>");
                    });
                }else{
                   /* alert("地址信息错误");*/
                }
            }/*,
            error : function() {
                alert("异常！");
            }*/
        });
    }
    function supplierNameSearch() {
        var local = $("[name='localSearch2'] option:selected").text();
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/querySupplierName" ,//url
            data:{local:local},
            success: function (result) {
                if (result.success>0) {
                    $("[name='supplierNameSearch2']").empty();
                    var op="";
                    var bp="请选择供应商名称";
                    $("[name='supplierNameSearch2']").append("<option value="+op+">"+bp+"</option>");
                    var list =result.date;
                    $.each(list,function (i,val) {
                        $("[name='supplierNameSearch2']").append("<option value="+val+">"+val+"</option>");
                    });
                }else{
                   /* alert("供应商信息错误");*/
                }
            }/*,
            error : function() {
                alert("异常！");
            }*/
        });

    }

    function goodsType() {
        var factory = $("[name='supplierNameSearch2'] option:selected").text();
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/sysMaterialManagement/querygoodsType" ,//url
            data:{factory:factory},
            success: function (result) {
                if (result.success>0) {
                    $("[name='goodsTypeSearch2']").empty();
                    var op="";
                    var bp="请选择物料类别";
                    $("[name='goodsTypeSearch2']").append("<option value="+op+">"+bp+"</option>");
                    var list =result.date;
                    $.each(list,function (i,val) {
                        var a =val.id;
                        var b =val.materialtype;
                        $("[name='goodsTypeSearch2']").append("<option value="+a+">"+b+"</option>");
                    });
                }else{
                    /*alert("类别信息错误");*/
                }
            }/*,
            error : function() {
                alert("异常！");
            }*/
        });
    }

    function goodsName() {
        var pid=$("[name='goodsTypeSearch2']").val();
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/sysMaterialManagement/queryByPid" ,//url
            data:{pid:pid},
            success: function (result) {
                if (result.success>0) {
                    $("[name='goodsNameSearch2']").empty();
                    var op="";
                    var bp="请选择物料名称";
                    $("[name='goodsNameSearch2']").append("<option value="+op+">"+bp+"</option>");
                    var list =result.date;
                    $.each(list,function (i,val) {
                        var a =val.id;
                        var b =val.materialName
                        $("[name='goodsNameSearch2']").append("<option value="+a+">"+b+"</option>");
                    });
                }else{
                    /*alert("名称信息错误");*/
                }
            }/*,
            error : function() {
                alert("异常！");
            }*/
        });
    }

    function specifications() {
        var pid = $("[name='goodsNameSearch2']").val();
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/sysMaterialManagement/queryByPid" ,//url
            data:{pid:pid},
            success: function (result) {
                if (result.success>0) {
                    $("[name='specificationsSearch2']").empty();
                    var op="";
                    var bp="请选择物料规格";
                    $("[name='specificationsSearch2']").append("<option value="+op+">"+bp+"</option>");
                    var list =result.date;
                    $.each(list,function (i,val) {
                        console.log(i+'```````'+val);
                        var a =val.id;
                        var b =val.materialSpecification;
                        $("[name='specificationsSearch2']").append("<option value="+a+">"+b+"</option>");
                    });
                }else{
                   /* alert("规格信息错误");*/
                }
            }/*,
            error : function() {
                alert("异常！");
            }*/
        });
    }
    var unSelected = "#999";
    var selected = "#333";
    $(function () {
        $("select").css("color", unSelected);
        $("option").css("color", selected);
        $("select").change(function () {
            var selItem = $(this).val();
            if (selItem == $(this).find('option:first').val()) {
                $(this).css("color", unSelected);
            } else {
                $(this).css("color", selected);
            }
        });
    })
</script>

</body>
</html>